package com.lsfb.signln.Login.Forget;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import com.lsfb.signln.Login.LoginActivity;
import com.lsfb.signln.R;
import com.lsfb.signln.Utils.LittleUtils;
import com.lsfb.signln.Utils.MyProgressDialog;
import com.lsfb.signln.Utils.URLString;
import com.zgscwjm.lsfbbasetemplate.Event.EventAnnotation;
import com.zgscwjm.lsfbbasetemplate.LsfbActivity;
import com.zgscwjm.lsfbbasetemplate.annotation.ContentView;
import com.zgscwjm.lsfbbasetemplate.annotation.OnClick;
import com.zgscwjm.lsfbbasetemplate.annotation.ViewInject;
import com.zgscwjm.lsfbbasetemplate.internet.BaseInternet;
import com.zgscwjm.lsfbbasetemplate.utils.T;

import java.util.HashMap;

/**
 * 忘记密码
 * Created by Administrator on 2018/1/23 0023.
 */
@ContentView(R.layout.aty_forget)
public class ForgetActicity extends LsfbActivity {

    /**
     * 手机号
     */
    @ViewInject(R.id.aty_forget_et_phone)
    private EditText et_phone;

    private MyProgressDialog dialog;

    @Override
    public void initView() {
        dialog = new MyProgressDialog(this, "正在获取验证码...");
    }

    @Override
    public void initEvent() {

    }

    /**
     * 点击事件
     *
     * @param view
     */
    @OnClick({R.id.aty_forget_img_back, R.id.aty_forget_img_del, R.id.aty_forget_et_next})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.aty_forget_img_back:
                finish();
                break;
            //删除手机号码
            case R.id.aty_forget_img_del:
                et_phone.setText("");
                break;
            //下一步
            case R.id.aty_forget_et_next:
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(et_phone.getWindowToken(), 0);

                getForgetPwdcc();
                break;
        }
    }

    @Override
    public void initData() {

    }

    /**
     * 获取验证码
     */
    public void getForgetPwdcc() {
        if (et_phone.getText().toString().isEmpty()) {
            T.showShort(this, "请输入手机号码");
            return;
        }
        HashMap<String, String> hashMap = new HashMap<String, String>();
        dialog.showdialog();
        hashMap.put("phone", et_phone.getText().toString());
        new BaseInternet().getData_Get(URLString.GETFORGETPWDCC, hashMap, String.class, new GetForgetPwdccEvent(), false, false);
    }

    @EventAnnotation
    public void GetForgetPwdccEvent(GetForgetPwdccEvent event) {
        dialog.hidedialog();
        switch (event.getCode()) {
            case 200:
                startActivity(new Intent(this, ForgetCodeActicity.class).putExtra("phone", et_phone.getText().toString()).putExtra("code", event.getData()));
                break;
            case 1006:
                T.showShort(this, "您的账号已在其它设备登录，请重登录");
                LittleUtils.exit(this);
                startActivity(new Intent(this, LoginActivity.class));
                break;
            default:
                T.showShort(this, event.getMsg());
                break;
        }
    }

}
